Imports System
Imports System.ComponentModel


<System.CodeDom.Compiler.GeneratedCodeAttribute("ViewModel Tool", "3.0.0.0")>  _
Partial Public Class Mock(Of T)
    Implements System.ComponentModel.ISupportInitialize, System.ComponentModel.ISupportInitializeNotification, System.ComponentModel.IChangeTracking, System.ComponentModel.INotifyPropertyChanged
    
    Const InitializationNotBegun As String = "Initialization has not been started."
    
    Const NotInitialized As String = "The object has not been initialized properly. Call Initialize prior to use."
    
    Private _initializing As Boolean
    
    Private _isInitialized As Boolean
    
    Private _isChanged As Boolean
    
    Protected Overridable ReadOnly Property IsInitializing() As Boolean
        Get
            Return Me._initializing
        End Get
    End Property
    
    Private ReadOnly Property RequiresInitialize() As Boolean
        Get
            Dim result As Boolean = (Me.IsInitialized = false)
            result = (result OrElse Me.IsChanged)
            Return result
        End Get
    End Property
    
    Public ReadOnly Property IsInitialized() As Boolean Implements ISupportInitializeNotification.IsInitialized
        Get
            Return (Me._isInitialized AndAlso Me.AreNestedInitialized)
        End Get
    End Property
    
    ''' <summary>Gets whether the object properties that support <see cref='ISupportInitializeNotification'/> are initialized.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overridable ReadOnly Property AreNestedInitialized() As Boolean
        Get
            Return true
        End Get
    End Property
    
    Public ReadOnly Property IsChanged() As Boolean Implements IChangeTracking.IsChanged
        Get
            Return Me._isChanged
        End Get
    End Property
    
    '''<summary>Signals that the object has been initialized.</summary>
    Public Event Initialized As EventHandler Implements ISupportInitializeNotification.Initialized
    
    '''<summary>Signals that a property has changed.</summary>
    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    
    '''<summary>Signals that the property <see cref='MyValue'/> has changed.</summary>
    Public Event MyValueChanged As EventHandler
    
    '''<summary>Initializes the object for use.</summary>
    Public Sub Initialize()
        If Me.RequiresInitialize Then
            Me.BeginInit
            Me.InitializeNested
            Me.EndInit
        End If
        Me.AcceptChanges
    End Sub
    
    '''<summary>Initializes the properties whose values support <see cref='ISupportInitialize'/>.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overridable Sub InitializeNested()
    End Sub
    
    Public Sub BeginInit() Implements ISupportInitialize.BeginInit
        Me._initializing = true
    End Sub
    
    Public Sub EndInit() Implements ISupportInitialize.EndInit
        If (Me._initializing = false) Then
            Throw New InvalidOperationException(Mock(Of T).InitializationNotBegun)
        End If
        Me.DoInitialize
        Me._initializing = false
        Me._isInitialized = true
        If (Not (Me.InitializedEvent) Is Nothing) Then
            RaiseEvent Initialized(Me, EventArgs.Empty)
        End If
    End Sub
    
    '''<summary>Determines whether the value is null or its 
    '''				<see cref='ISupportInitializeNotification.IsInitialized'/> is <see langword='true' />.
    '''				</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Function IsValueInitialized(ByVal child As ISupportInitializeNotification) As Boolean
        Return ((child Is Nothing)  _
                    OrElse child.IsInitialized)
    End Function
    
    Public Sub AcceptChanges() Implements IChangeTracking.AcceptChanges
        Me._isChanged = false
    End Sub
    
    '''<summary>Raises the <see cref='PropertyChanged'/> event.</summary>
    '''					  <param name='property'>Name of the property that changed.</param>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Sub RaisePropertyChanged(ByVal [property] As String)
        If (Me.IsInitializing = true) Then
            Return
        End If
        If (Not (Me.PropertyChangedEvent) Is Nothing) Then
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs([property]))
        End If
        Me._isChanged = true
    End Sub
    
    '''<summary>Raises the <see cref='MyValueChanged'/> event.</summary>
    Private Sub RaiseMyValueChanged()
        If (Me.IsInitializing = true) Then
            Return
        End If
        If (Not (Me.MyValueChangedEvent) Is Nothing) Then
            RaiseEvent MyValueChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("MyValue")
    End Sub
End Class


<System.CodeDom.Compiler.GeneratedCodeAttribute("ViewModel Tool", "3.0.0.0")>  _
Partial Public Class MockBase
    Implements System.ComponentModel.ISupportInitialize, System.ComponentModel.ISupportInitializeNotification, System.ComponentModel.IChangeTracking, System.ComponentModel.INotifyPropertyChanged
    
    Const InitializationNotBegun As String = "Initialization has not been started."
    
    Const NotInitialized As String = "The object has not been initialized properly. Call Initialize prior to use."
    
    Private _initializing As Boolean
    
    Private _isInitialized As Boolean
    
    Private _isChanged As Boolean
    
    Protected Overridable ReadOnly Property IsInitializing() As Boolean
        Get
            Return Me._initializing
        End Get
    End Property
    
    Private ReadOnly Property RequiresInitialize() As Boolean
        Get
            Dim result As Boolean = (Me.IsInitialized = false)
            result = (result OrElse Me.IsChanged)
            Return result
        End Get
    End Property
    
    Public ReadOnly Property IsInitialized() As Boolean Implements ISupportInitializeNotification.IsInitialized
        Get
            Return (Me._isInitialized AndAlso Me.AreNestedInitialized)
        End Get
    End Property
    
    ''' <summary>Gets whether the object properties that support <see cref='ISupportInitializeNotification'/> are initialized.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overridable ReadOnly Property AreNestedInitialized() As Boolean
        Get
            Return (true AndAlso Me.IsValueInitialized(TryCast(BaseObject, ISupportInitializeNotification)))
        End Get
    End Property
    
    Public ReadOnly Property IsChanged() As Boolean Implements IChangeTracking.IsChanged
        Get
            Return Me._isChanged
        End Get
    End Property
    
    '''<summary>Signals that the object has been initialized.</summary>
    Public Event Initialized As EventHandler Implements ISupportInitializeNotification.Initialized
    
    '''<summary>Signals that a property has changed.</summary>
    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    
    '''<summary>Signals that the property <see cref='BaseIntValue'/> has changed.</summary>
    Public Event BaseIntValueChanged As EventHandler
    
    '''<summary>Signals that the property <see cref='BaseObject'/> has changed.</summary>
    Public Event BaseObjectChanged As EventHandler
    
    '''<summary>Initializes the object for use.</summary>
    Public Sub Initialize()
        If Me.RequiresInitialize Then
            Me.BeginInit
            Me.InitializeNested
            Me.EndInit
        End If
        Me.AcceptChanges
    End Sub
    
    '''<summary>Initializes the properties whose values support <see cref='ISupportInitialize'/>.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overridable Sub InitializeNested()
        Dim initializable As ISupportInitialize
        initializable = TryCast(BaseObject, ISupportInitialize)
        If (Not (initializable) Is Nothing) Then
            initializable.BeginInit
            initializable.EndInit
        End If
    End Sub
    
    Public Sub BeginInit() Implements ISupportInitialize.BeginInit
        Me._initializing = true
    End Sub
    
    Public Sub EndInit() Implements ISupportInitialize.EndInit
        If (Me._initializing = false) Then
            Throw New InvalidOperationException(MockBase.InitializationNotBegun)
        End If
        Me.DoInitialize
        Me._initializing = false
        Me._isInitialized = true
        If (Not (Me.InitializedEvent) Is Nothing) Then
            RaiseEvent Initialized(Me, EventArgs.Empty)
        End If
    End Sub
    
    '''<summary>Determines whether the value is null or its 
    '''				<see cref='ISupportInitializeNotification.IsInitialized'/> is <see langword='true' />.
    '''				</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Function IsValueInitialized(ByVal child As ISupportInitializeNotification) As Boolean
        Return ((child Is Nothing)  _
                    OrElse child.IsInitialized)
    End Function
    
    Public Sub AcceptChanges() Implements IChangeTracking.AcceptChanges
        Me._isChanged = false
        Dim tracked As IChangeTracking
        tracked = TryCast(BaseObject, IChangeTracking)
        If (Not (tracked) Is Nothing) Then
            tracked.AcceptChanges
        End If
    End Sub
    
    '''<summary>Raises the <see cref='PropertyChanged'/> event.</summary>
    '''					  <param name='property'>Name of the property that changed.</param>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Sub RaisePropertyChanged(ByVal [property] As String)
        If (Me.IsInitializing = true) Then
            Return
        End If
        If (Not (Me.PropertyChangedEvent) Is Nothing) Then
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs([property]))
        End If
        Me._isChanged = true
    End Sub
    
    '''<summary>Raises the <see cref='BaseIntValueChanged'/> event.</summary>
    Private Sub RaiseBaseIntValueChanged()
        If (Me.IsInitializing = true) Then
            Return
        End If
        If (Not (Me.BaseIntValueChangedEvent) Is Nothing) Then
            RaiseEvent BaseIntValueChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("BaseIntValue")
    End Sub
    
    '''<summary>Raises the <see cref='BaseObjectChanged'/> event.</summary>
    Private Sub RaiseBaseObjectChanged()
        If (Me.IsInitializing = true) Then
            Return
        End If
        If (Not (Me.BaseObjectChangedEvent) Is Nothing) Then
            RaiseEvent BaseObjectChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("BaseObject")
        Dim inotify As INotifyPropertyChanged = TryCast(BaseObject, INotifyPropertyChanged)
        If (Not (inotify) Is Nothing) Then
            AddHandler inotify.PropertyChanged, AddressOf Me.HandleBaseObjectChanged
        End If
    End Sub
    
    Private Sub HandleBaseObjectChanged(ByVal sender As Object, ByVal args As PropertyChangedEventArgs)
        If (Not (Me.BaseObjectChangedEvent) Is Nothing) Then
            RaiseEvent BaseObjectChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("BaseObject")
    End Sub
End Class


<System.CodeDom.Compiler.GeneratedCodeAttribute("ViewModel Tool", "3.0.0.0")>  _
Partial Public Class MockDerived
    
    ''' <summary>Gets whether the object properties that support <see cref='ISupportInitializeNotification'/> are initialized.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overrides ReadOnly Property AreNestedInitialized() As Boolean
        Get
            Return ((MyBase.AreNestedInitialized AndAlso Me.IsValueInitialized(TryCast(DerivedObject, ISupportInitializeNotification)))  _
                        AndAlso Me.IsValueInitialized(CType(Me.Mock,ISupportInitializeNotification)))
        End Get
    End Property
    
    '''<summary>Signals that the property <see cref='DerivedIntValue'/> has changed.</summary>
    Public Event DerivedIntValueChanged As EventHandler
    
    '''<summary>Signals that the property <see cref='DerivedObject'/> has changed.</summary>
    Public Event DerivedObjectChanged As EventHandler
    
    '''<summary>Signals that the property <see cref='Mock'/> has changed.</summary>
    Public Event MockChanged As EventHandler
    
    '''<summary>Initializes the nested properties that support <see cref='ISupportInitialize'/>.</summary>
    <EditorBrowsableAttribute(EditorBrowsableState.Never)>  _
    Protected Overrides Sub InitializeNested()
        MyBase.InitializeNested
        Dim initializable As ISupportInitialize
        initializable = TryCast(DerivedObject, ISupportInitialize)
        If (Not (initializable) Is Nothing) Then
            initializable.BeginInit
            initializable.EndInit
        End If
        initializable = CType(Me.Mock,ISupportInitialize)
        If (Not (initializable) Is Nothing) Then
            initializable.BeginInit
            initializable.EndInit
        End If
    End Sub
    
    '''<summary>Raises the <see cref='DerivedIntValueChanged'/> event.</summary>
    Private Sub RaiseDerivedIntValueChanged()
        If (Me.IsInitializing = true) Then
            Return
        End If
        If (Not (Me.DerivedIntValueChangedEvent) Is Nothing) Then
            RaiseEvent DerivedIntValueChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("DerivedIntValue")
    End Sub
    
    '''<summary>Raises the <see cref='DerivedObjectChanged'/> event.</summary>
    Private Sub RaiseDerivedObjectChanged()
        If (Me.IsInitializing = true) Then
            Return
        End If
        If (Not (Me.DerivedObjectChangedEvent) Is Nothing) Then
            RaiseEvent DerivedObjectChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("DerivedObject")
        Dim inotify As INotifyPropertyChanged = TryCast(DerivedObject, INotifyPropertyChanged)
        If (Not (inotify) Is Nothing) Then
            AddHandler inotify.PropertyChanged, AddressOf Me.HandleDerivedObjectChanged
        End If
    End Sub
    
    Private Sub HandleDerivedObjectChanged(ByVal sender As Object, ByVal args As PropertyChangedEventArgs)
        If (Not (Me.DerivedObjectChangedEvent) Is Nothing) Then
            RaiseEvent DerivedObjectChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("DerivedObject")
    End Sub
    
    '''<summary>Raises the <see cref='MockChanged'/> event.</summary>
    Private Sub RaiseMockChanged()
        If (Me.IsInitializing = true) Then
            Return
        End If
        If (Not (Me.MockChangedEvent) Is Nothing) Then
            RaiseEvent MockChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("Mock")
        Dim inotify As INotifyPropertyChanged = CType(Me.Mock,INotifyPropertyChanged)
        If (Not (inotify) Is Nothing) Then
            AddHandler inotify.PropertyChanged, AddressOf Me.HandleMockChanged
        End If
    End Sub
    
    Private Sub HandleMockChanged(ByVal sender As Object, ByVal args As PropertyChangedEventArgs)
        If (Not (Me.MockChangedEvent) Is Nothing) Then
            RaiseEvent MockChanged(Me, EventArgs.Empty)
        End If
        Me.RaisePropertyChanged("Mock")
    End Sub
End Class
